class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


def visitTree(root: TreeNode):
    queue = []
    res = []
    queue.append(root)
    while(len(queue) != 0):
        t = queue.pop(0)
        res.append('null' if(t == None) else t.val)
        if(t):
            queue.append(t.left)
            queue.append(t.right)

    for i in range(len(res)-1, -1, -1):
        if(res[i] == 'null'):
            res.pop(i)
        else:
            break
    print(res)
